#include "ParticleManager.h"
#include "Emitter.h"

 ParticleManager* ParticleManager::s_Instance = NULL;

ParticleManager::ParticleManager(void)
{
	curEmitter = 0;
}

ParticleManager::~ParticleManager(void)
{
}

// Read in file w/ the types of emitters
void ParticleManager::Init(void)
{
	emitterTypes.push_back("Test");
	curEmitter = 0;
}

ParticleManager* ParticleManager::GetInstance(void)
{
	if( s_Instance == NULL )
		s_Instance = new ParticleManager();

	return s_Instance;
}

void ParticleManager::Shutdown(void)
{
	s_Instance->ClearEmitters();
	delete s_Instance;
	s_Instance = NULL;
}

// create a new emitter of a specified type
// and adding it to the list
void ParticleManager::AddEmitter(unsigned int nType)
{
	m_pEmitters[curEmitter++].Init(emitterTypes[nType]);
	if( curEmitter > EMITTER_COUNT )
		curEmitter = 0;
}

void ParticleManager::ClearEmitters(void)
{
	for(int i = 0; i < EMITTER_COUNT; i++)
		m_pEmitters[i].Destroy();
}

void ParticleManager::Update(float fElapsedTime)
{
	for(int i = 0; i < EMITTER_COUNT; i++)
		if( m_pEmitters[i].isAlive() )
			m_pEmitters[i].Update(fElapsedTime);
}

void ParticleManager::Render(void)
{
	for(int i = 0; i < EMITTER_COUNT; i++)
		if( m_pEmitters[i].isAlive() )
			m_pEmitters[i].Render();
}